package com.icarcom.cn.ui.util;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.icarcom.cn.MainActivity;
import com.icarcom.cn.R;
import com.icarcom.cn.util.T;
import com.lvfq.pickerview.adapter.ArrayWheelAdapter;
import com.lvfq.pickerview.lib.WheelView;
import com.lxj.xpopup.core.BottomPopupView;
import com.lxj.xpopup.util.XPopupUtils;

import java.util.ArrayList;

import androidx.annotation.NonNull;

public class MainTypePopup extends BottomPopupView implements View.OnClickListener{

    WheelView wv_device_option;
    ArrayList<String> NameList = new ArrayList<>();
    TextView tv_main_type_start;
    private ShopDeatilListener listener;
    Activity activity;

    public MainTypePopup(@NonNull Context context) {
        super(context);
    }

    public interface ShopDeatilListener{
        public void onClick(View view);
    }

    public MainTypePopup(@NonNull Activity activity, ShopDeatilListener listener,ArrayList<String> NameList) {
        super(activity);
        // TODO Auto-generated constructor stub
        this.activity = activity;
        this.listener = listener;
        this.NameList = NameList;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.pop_main_type;
    }


    @Override
    protected void onCreate() {
        super.onCreate();

        wv_device_option = findViewById(R.id.wv_device_option);
        tv_main_type_start = findViewById(R.id.tv_main_type_start);

        wv_device_option.setAdapter(new ArrayWheelAdapter(NameList));
        wv_device_option.setCyclic(false);//设置是否循环显示，如果不循环，到WheelView中设置从第几个显示
        wv_device_option.setTextSize(15);

        tv_main_type_start.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                MainActivity.instance.tv_main_type.setText(NameList.get(wv_device_option.getCurrentItem()));
                MainActivity.instance.code = MainActivity.instance.CodeList.get(wv_device_option.getCurrentItem());

                dismiss();
            }
        });
    }

    @Override
    protected void onShow() {
        super.onShow();
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
    }

    @Override
    protected int getMaxHeight() {
        return (int) (XPopupUtils.getScreenHeight(getContext())*.6f);
    }

    @Override
    public void onClick(View view) {
        listener.onClick(view);
    }
}
